{% extends "cmdb/mequipment/index.html" %}

{% block right_content %}
<div id="right_menu">
    <button id="add" type="button" class="btn btn-info hint hint-top" data-hint="添加一个机房信息" data-toggle="modal" data-target="#addItem"><span class="glyphicon glyphicon-plus"></span></button>
    <table id="example" style="table-layout:fixed;" class="table table-bordered table-hover">
        <thead >
        <td class="col">编号</td>
        <td class="col">机房名</td>
        <td class="col">机房电话</td>
        <td class="col">机房地址</td>
        <td class="col">操作</td>
        </thead>
        {% if server_room_list %}
        {% for server_room in server_room_list %}
        <tr>
            <td class="col">{{ server_room.id }}</td>
            <td class="col">{{ server_room.server_room }}</td>
            <td class="col">{{ server_room.phone }}</td>
            <td class="col">{{ server_room.server_room_addr }}</td>
            <td class="col">
                <div>
                    <a  class="edit_item hint hint-top mouse_pointer" data-hint="编辑机房信息" data-id="{{ server_room.id }}" data-toggle="modal" data-target="#editItem">
                        <span class="glyphicon glyphicon-edit"></span>                   
                    </a>&nbsp;
                    <a data-id="{{ server_room.id }}" class="delete_item hint hint-top mouse_pointer" data-hint="删除机房信息">
                        <span class="glyphicon glyphicon-trash"></span>
                    </a>
                </div>
            </td>
        </tr>
        {% endfor %}
        {% endif %}
    </table>

    <div>
        <span>跳转到
         <select class="pagei">
             {% for temppage in page_list %}
             <option value="{{ temppage }}" {% ifequal temppage page %}selected {% endifequal %}>{{ temppage }}</option>
             {% endfor %}
         </select>页
        </span>
        <span style="padding-left: 28%;">每页{{ page_num }}条，第{{ page }}页，共{{ count }}条，共{{ page_total }}页</span>
        <span style="float:right;padding-right:50px">

            <a class="word hint hint-top" data-hint="首页" href="{% url 'equipment:roominfo' %}?page=1"><span class="glyphicon glyphicon-fast-backward"></span></a>
            {% ifnotequal page 1 %}&nbsp;
            <a class="hint hint-top" data-hint="上一页" href="{% url 'equipment:roominfo' %}?page={{ page|add:-1 }}"><span class="glyphicon glyphicon-step-backward"></span></a>
            {% endifnotequal %}

            {% ifnotequal page page_total %}&nbsp;
            <a class="hint hint-top" data-hint="下一页" href="{% url  'equipment:roominfo' %}?page={{ page|add:1 }}"><span class="glyphicon glyphicon-step-forward"></span></a>
            {% endifnotequal %}&nbsp;
            <a class="word hint hint-top" data-hint="尾页" href="{% url 'equipment:roominfo' %}?page={{ page_total }}"><span class="glyphicon glyphicon-fast-forward"></span></a>

        </span>
    </div>
</div>

<script type="text/javascript">
$(".pagei").change(function(){
        var index=$(this).children('option:selected').val();
        window.location.href="{% url 'equipment:roominfo' %}?page=" +index;
});
$("#add").click(function(){
    window.location.href="{% url 'equipment:saddinfo' %}";
});
$(".edit_item").click(function(){
    var id = $(this).data("id");
    window.location.href="{% url 'equipment:seditinfo' %}?page=" + {{ page }} + "&id="+id;
});
$(".delete_item").click(function(){
    if(confirm("确定要删除吗？删除操作不可恢复！")) {
           var id = $(this).data("id");
           var urls = "{% url 'equipment:sdelete' %}";
           var postdata = {id:id}
           var jsonstr = $.ajax({
			    url : urls,
			    type : "POST",
			    data : postdata,
			    async : false,
			    cache : false
		    });
	     var jsonobj = eval('(' + jsonstr.responseText + ')');
		  if(jsonobj.status==0){
		      alert(jsonobj.message);
		  }else{
              window.location.reload();
          }
     }
});
</script>
{% endblock  %}

